{% extends "manager.html" %}
	{% block style %}
        <link rel="stylesheet" href="static/css/editormd.css" />
	{% end %}
	{% block body %}
	<div class="w90">
        <div id="layout" style="width:90%">
            <header>
			<div style="width:60%;float:left">
				文章主题：<input type="text" style="width:60%" id="subject"  value="{{ subject }}"></br>
				文章标签：<input type="text" style="width:60%" id='tags'  value="{{ tags }}"></br>
				文章类别：<select  style="width:40%" id="Category">
								{% for i in conf['Category'] %}
								<option value="{{ i[1] }}">{{ i[1] }}</option>
								{% end %}
								</select>&nbsp;&nbsp;<a href="#" class="btn btn-sm btn-primary" id="cconf">管理类别</a>
			</div>
			<div style="width:40%;float:right">
			<br />
			<button class="btn btn-success btn-large btn-block" id="editsub" type="button">确认OK，立刻发布我的文章</button>
			</div>
            </header>
		</div>

        <div id="editormd">
        <textarea style="display:none;">{{ markdown }}</textarea>
        </div>
        </div>
<!-- LB-->
<div class="modal fade" id="LB" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog w35">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="add"><b>文章类别管理：</b></h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		{% for i in conf['Category'] %}
		{% if i[0] !=' ' %}
		<label><input name="LB" type="checkbox" value="{{ i[0] }}" />{{ i[1] }}
		</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		{% end %}
		{% end %}
	    </div>
      </div>
	  <div class="modal-footer">
        <button type="button" id="new" class="btn btn-default">新增一个类别</button>
        <button type="button" id="del" class="btn btn-primary">刪除选中项</button>
      </div>
    </div>
  </div>
</div>
<!-- add-->
<div class="modal fade" id="newadd" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog w35">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="add"><b>新增类别：</b></h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		<table class="w90">
			<tr><td>新增类别:</td><td><input type="text" class="form-control" id='addname'></td></tr>
		</table>
	    </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" id="addsub" class="btn btn-primary">新增</button>
      </div>
    </div>
  </div>
</div>
	{% end %}
	{% block js %}
		<script src="static/js/editormd.js"></script>
        <script type="text/javascript">
			var testEditor;
			var xsrf=$.cookie("_xsrf")
            $(function() {
                testEditor = editormd("editormd", {
                    width   : "100%",
                    height  : 640,
                    path    : "static/lib/",
					imageUpload : true,
					imageFormats : ["jpg", "jpeg", "gif", "png", "bmp"],
					imageUploadURL : "upload",
                });
                $("#editsub").bind('click', function(){
					 $.proxy(
					 $.post("edit",{markdown:testEditor.getValue(),
									subject:$("#subject").val(),
									tags:$("#tags").val(),
									Category:$("#Category").val(),
									TYPE:"{{TYPE}}",
									ID:"{{ID}}",
									_xsrf:xsrf},
						function(data){alert(data)}
					 ),testEditor);
					})
                /*
                // or
                testEditor = editormd({
                    id      : "test-editormd",
                    width   : "90%",
                    height  : 640,
                    path    : "../lib/"
                });
                */
            });

		$(document).ready(function(){
			if("{{LEIBIE}}"!=""){$("#Category").val("{{LEIBIE}}")}
			})
			
		$("#cconf").click((function(){$("#LB").modal()}));
		$("#new").click((function(){
			$("#LB").modal('hide')
			$("#newadd").modal();
			}));
		$("#del").click((function(){
			var Category=''
			$("[name='LB']:checkbox:checked").each(function(){
			Category += $(this).val() + ',';
			})
			if (Category==''){alert('你未选中任何项目！')} else {
			$.post("/edit",{_xsrf:xsrf,TYPE:'DEL',Category:Category},function(data){alert(data);location.reload();})
				}
			}));
		$("#addsub").click((function(){
			var newlb=$("#addname").val()
			if (newlb==''){alert('不能为空值！')} else {
			$.post("/edit",{_xsrf:xsrf,TYPE:'NEW',Category:newlb},function(data){alert(data);location.reload();})
			}
			}));
		</script>
	{% end %}
